package com.spring.hed.factory.adapter;

import java.util.Arrays;

interface Processor {
    String name();

    Object process(Object input);
}

/**
 * 公共方法，继承他也实现了Processos
 */
abstract class StringProcess implements Processor{

    public String name(){
        return getClass().getSimpleName();
    }
}

class Upcase extends StringProcess{

    public String process(Object input){
        return ((String)input).toUpperCase();
    }
}

class Downcase extends StringProcess{
    public String process(Object input){
        return ((String) input).toLowerCase();
    }
}

class Splitter extends StringProcess{
    public String process(Object input){
        return Arrays.toString(((String) input).split(" "));
    }
}

/**
 * 可复用性更高
 */
class Apply{
    public static void process(Processor p , Object o){
        System.out.println(p.name());
        System.out.println(p.process(o));
    }
}

/**
 * 适配器
 */
class FilterAdapter implements Processor {

    Filter filter;

    public FilterAdapter(Filter filter) {
        this.filter = filter;
    }

    public String name() {
        return filter.name();
    }

    public WaveForm process(Object input) {
        return filter.process((WaveForm)input);
    }
}